package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@Slf4j
@Api(tags = "预约列表")
public class OrderController {
    @Autowired
    private OrderService orderService;
    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @PostMapping("/findPage")
    @ApiOperation("分页查询")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return orderService.findPage(queryPageBean);
    }

    /**
     * 修改状态
     * @param
     * @param order
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("修改状态")
    public Result update(@RequestBody Order order){
        log.info("修改状态，id:{},orderStatus:{}",order.getId(),order.getOrderStatus());
        try {
            orderService.update(order.getId(),order.getOrderStatus());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.UPDATE_ORDERSTATUS_FAIL);
        }
        return new Result(true, MessageConstant.UPDATE_ORDERSTATUS_SUCCESS);
    }
}
